---
title: "OLS"
output: 
  html_document:
    toc: true
    toc_float: true
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r packages, message=FALSE,include=FALSE}
library(rio)
library(dplyr)
library(reshape2)
library(lme4)
library(jtools)
library(ggeffects)
library(ggplot2)
library(patchwork)
```

```{r data,message=FALSE,include=FALSE}
corrections_uk <- import("uk.sav", setclass="tibble")
corrections_brazil <- import("brazil.sav", setclass="tibble")
corrections_brazil <- corrections_brazil %>%
  rename(attentioncheck1= attention_check1)

corrections_india <- import("india.sav", setclass="tibble")

corrections_uk$country <- "UK"
corrections_brazil$country <- "Brazil"
corrections_india$country <- "India"

corrections_merged <- bind_rows(corrections_uk, corrections_brazil, corrections_india)

corrections_merged <- corrections_merged %>%
  filter(consent==1) %>%
  filter(debrief_1 != "NA")
```

```{r recoding, message=FALSE,include=FALSE}
corrections_merged <- corrections_merged %>%
  mutate(false_1_accuracy = ifelse(country == "UK", coalesce(A1_dv_accurate_link,A1_dv_accurate_nolink,A1_dv_accurate_control),
                            ifelse(country == "Brazil", coalesce(A6_dv_accurate_link,A6_dv_accurate_nolink,A6_dv_accurate_nocorrec),
                                                     coalesce(A7_dv_accurate_link,A7_dv_accurate_nolink,A9_dv_accurate_nocorrec)))) %>%
  mutate(false_2_accuracy = ifelse(country == "UK", coalesce(A2_dv_accurate_link,A2_dv_accurate_nolink,A2_dv_accurate_control),
                            ifelse(country == "Brazil", coalesce(A7_dv_accurate_link,A7_dv_accurate_nolink,A3_dv_accurate_nocorrec),
                                                     coalesce(A3_dv_accurate_link,A3_dv_accurate_nolink,A3_dv_accurate_nocorrec)))) %>%  
  mutate(false_3_accuracy = ifelse(country == "UK", coalesce(A3_dv_accurate_link,A3_dv_accurate_nolink,A3_dv_accurate_control),
                            ifelse(country == "Brazil", coalesce(A8_dv_accurate_link,A8_dv_accurate_nolink,A8_dv_accurate_nocorrec),
                                                     coalesce(A1_dv_accurate_link,A1_dv_accurate_nolink,A1_dv_accurate_nocorrec)))) %>%
  mutate(false_4_accuracy = ifelse(country == "UK", coalesce(A4_dv_accurate_link,A4_dv_accurate_nolink,A4_dv_accurate_control),
                            ifelse(country == "Brazil", coalesce(A9_dv_accurate_link,A9_dv_accurate_nolink,A1_dv_accurate_nocorrec),
                                                     coalesce(A5_dv_accurate_link,A5_dv_accurate_nolink,A5_dv_accurate_nocorrec)))) %>% 
  
  mutate(uncorrected_1_accuracy = ifelse(country == "UK", coalesce(A10_dv_accurate_link,A10_dv_accurate_nolink,A10_dv_accurate_control),
                                ifelse(country == "Brazil", coalesce(A10_dv_accurate_link,A10_dv_accurate_nolink,A9_dv_accurate_nocorrec),
                                                     coalesce(A8_dv_accurate_link,A8_dv_accurate_nolink,A10_dv_accurate_nocorrec)))) %>% 
  mutate(uncorrected_2_accuracy = ifelse(country == "UK", coalesce(A11_dv_accurate_link,A11_dv_accurate_nolink,A11_dv_accurate_control),
                                ifelse(country == "Brazil", coalesce(A11_dv_accurate_link,A12_dv_accurate_nolink,A11_dv_accurate_nocorrec),
                                                     coalesce(A9_dv_accurate_link,A9_dv_accurate_nolink,A12_dv_accurate_nocorrec)))) %>% 

  mutate(real_1_accuracy = ifelse(country == "UK", coalesce(A7_dv_accurate_link,A7_dv_accurate_nolink,A7_dv_accurate_control),
                           ifelse(country == "Brazil", coalesce(A2_dv_accurate_link,A2_dv_accurate_nolink,A2_dv_accurate_nocorrec),
                                                     coalesce(A2_dv_accurate_link,A2_dv_accurate_nolink,A2_dv_accurate_nocorrec)))) %>%   
  mutate(real_2_accuracy = ifelse(country == "UK", coalesce(A8_dv_accurate_link,A8_dv_accurate_nolink,A8_dv_accurate_control),
                           ifelse(country == "Brazil", coalesce(A4_dv_accurate_link,A4_dv_accurate_nolink,A4_dv_accurate_nocorrec),
                                                     coalesce(A4_dv_accurate_link,A4_dv_accurate_nolink,A4_dv_accurate_nocorrec)))) %>% 
  mutate(real_3_accuracy = ifelse(country == "UK", coalesce(A9_dv_accurate_link,A9_dv_accurate_nolink,A9_dv_accurate_control),
                           ifelse(country == "Brazil", coalesce(A5_dv_accurate_link,A5_dv_accurate_nolink,A5_dv_accurate_nocorrec),
                                                      coalesce(A6_dv_accurate_link,A6_dv_accurate_nolink,A6_dv_accurate_nocorrec))))

corrections_merged <- corrections_merged %>%
  mutate(false_1_sharing = ifelse(country == "UK", coalesce(A1_dv_share_link,A1_dv_share_nolink,A1_dv_share_control),
                            ifelse(country == "Brazil", coalesce(A6_dv_share_link,A6_dv_share_nolink,A6_dv_share_nocorrec),
                                                     coalesce(A7_dv_share_link,A7_dv_share_nolink,A9_dv_share_nocorrec)))) %>%
  mutate(false_2_sharing = ifelse(country == "UK", coalesce(A2_dv_share_link,A2_dv_share_nolink,A2_dv_share_control),
                            ifelse(country == "Brazil", coalesce(A7_dv_share_link,A7_dv_share_nolink,A3_dv_share_nocorrec),
                                                     coalesce(A3_dv_share_link,A3_dv_share_nolink,A3_dv_share_nocorrec)))) %>%  
  mutate(false_3_sharing = ifelse(country == "UK", coalesce(A3_dv_share_link,A3_dv_share_nolink,A3_dv_share_control),
                            ifelse(country == "Brazil", coalesce(A8_dv_share_link,A8_dv_share_nolink,A8_dv_share_nocorrec),
                                                     coalesce(A1_dv_share_link,A1_dv_share_nolink,A1_dv_share_nocorrec)))) %>%
  mutate(false_4_sharing = ifelse(country == "UK", coalesce(A4_dv_share_link,A4_dv_share_nolink,A4_dv_share_control),
                            ifelse(country == "Brazil", coalesce(A9_dv_share_link,A9_dv_share_nolink,A1_dv_share_nocorrec),
                                                     coalesce(A5_dv_share_link,A5_dv_share_nolink,A5_dv_share_nocorrec)))) %>% 
  
  mutate(uncorrected_1_sharing = ifelse(country == "UK", coalesce(A10_dv_share_link,A10_dv_share_nolink,A10_dv_share_control),
                                ifelse(country == "Brazil", coalesce(A10_dv_share_link,A10_dv_share_nolink,A9_dv_share_nocorrec),
                                                     coalesce(A8_dv_share_link,A8_dv_share_nolink,A10_dv_share_nocorrec)))) %>% 
  mutate(uncorrected_2_sharing = ifelse(country == "UK", coalesce(A11_dv_share_link,A11_dv_share_nolink,A11_dv_share_control),
                                ifelse(country == "Brazil", coalesce(A11_dv_share_link,A12_dv_share_nolink,A11_dv_share_nocorrec),
                                                     coalesce(A9_dv_share_link,A9_dv_share_nolink,A12_dv_share_nocorrec)))) %>% 

  mutate(real_1_sharing = ifelse(country == "UK", coalesce(A7_dv_share_link,A7_dv_share_nolink,A7_dv_share_control),
                           ifelse(country == "Brazil", coalesce(A2_dv_share_link,A2_dv_share_nolink,A2_dv_share_nocorrec),
                                                     coalesce(A2_dv_share_link,A2_dv_share_nolink,A2_dv_share_nocorrec)))) %>%   
  mutate(real_2_sharing = ifelse(country == "UK", coalesce(A8_dv_share_link,A8_dv_share_nolink,A8_dv_share_control),
                           ifelse(country == "Brazil", coalesce(A4_dv_share_link,A4_dv_share_nolink,A4_dv_share_nocorrec),
                                                     coalesce(A4_dv_share_link,A4_dv_share_nolink,A4_dv_share_nocorrec)))) %>% 
  mutate(real_3_sharing = ifelse(country == "UK", coalesce(A9_dv_share_link,A9_dv_share_nolink,A9_dv_share_control),
                           ifelse(country == "Brazil", coalesce(A5_dv_share_link,A5_dv_share_nolink,A5_dv_share_nocorrec),
                                                     coalesce(A6_dv_share_link,A6_dv_share_nolink,A6_dv_share_nocorrec))))

corrections_merged$country <- factor(corrections_merged$country)

corrections_merged$condition[corrections_merged$condition=="correction_link"] <- "link"
corrections_merged$condition[corrections_merged$condition=="correction_nolink" | corrections_merged$condition=="nolink"] <- "correction"
corrections_merged$condition <- factor(corrections_merged$condition)

corrections_merged$consp_mean <- (corrections_merged$consp_id1 + corrections_merged$consp_id2 + corrections_merged$consp_id3 + corrections_merged$consp_id4)/4
```

```{r reshaping,include=FALSE}
names(corrections_merged)[names(corrections_merged) == "covid_trust_1"] <- "Trust_Scientist"
names(corrections_merged)[names(corrections_merged) == "covid_trust_2"] <- "Trust_Ordinary_ppl"
names(corrections_merged)[names(corrections_merged) == "covid_trust_5"] <- "Trust_SM"
names(corrections_merged)[names(corrections_merged) == "covid_trust_3"] <- "Trust_News"

corrections_accuracy_long <- melt(corrections_merged, id.vars = c("ResponseId", "condition", "country", "consp_mean","Trust_SM","Trust_News","Trust_Scientist","Trust_Ordinary_ppl","age","gender","education"), 
              measure.vars = c("false_1_accuracy", "false_2_accuracy", "false_3_accuracy", "false_4_accuracy"), 
              variable.name = "post", 
              value.name="accuracy")

corrections_sharing_long <- melt(corrections_merged, id.vars = c("ResponseId", "condition", "country", "consp_mean","Trust_SM","Trust_News","Trust_Scientist","Trust_Ordinary_ppl","age","gender","education"), 
              measure.vars = c("false_1_sharing", "false_2_sharing", "false_3_sharing", "false_4_sharing"), 
              variable.name = "post", 
              value.name="sharing")

corrections_all_long <- melt(corrections_merged, id.vars = c("ResponseId", "condition", "country", "consp_mean","Trust_SM","Trust_News","Trust_Scientist","Trust_Ordinary_ppl","age","gender","education"), 
              measure.vars = c("false_1_sharing", "false_2_sharing", "false_3_sharing", "false_4_sharing","false_1_accuracy", "false_2_accuracy", "false_3_accuracy", "false_4_accuracy"), 
              variable.name = "post", 
              value.name="DV")
```

## Hypotheses

## H1a
### Models

```{r h1a_model}
library(sandwich)
library(lmtest)
ols_uk <- lm(accuracy ~ condition, data = subset(corrections_accuracy_long, country == "UK"))
clustered_se <- vcovCL(ols_uk, cluster = ~ResponseId+post)
coeftest(ols_uk, vcov = clustered_se)

ols_BRA <- lm(accuracy ~ condition, data = subset(corrections_accuracy_long, country == "Brazil"))
clustered_se <- vcovCL(ols_BRA, cluster = ~ResponseId+post)
coeftest(ols_BRA, vcov = clustered_se)

ols_IND <- lm(accuracy ~ condition, data = subset(corrections_accuracy_long, country == "India"))
clustered_se <- vcovCL(ols_IND, cluster = ~ResponseId+post)
coeftest(ols_IND, vcov = clustered_se)
```

## H1b
### Models

```{r h1b_model}
ols_uk <- lm(sharing ~ condition, data = subset(corrections_sharing_long, country == "UK"))
clustered_se <- vcovCL(ols_uk, cluster = ~ResponseId+post)
coeftest(ols_uk, vcov = clustered_se)

ols_BRA <- lm(sharing ~ condition , data = subset(corrections_sharing_long, country == "Brazil"))
clustered_se <- vcovCL(ols_BRA, cluster = ~ResponseId+post)
coeftest(ols_BRA, vcov = clustered_se)

ols_IND <- lm(sharing ~ condition , data = subset(corrections_sharing_long, country == "India"))
clustered_se <- vcovCL(ols_IND, cluster = ~ResponseId+post)
coeftest(ols_IND, vcov = clustered_se)

```
